package com.caipos.mqtt.entity;

import com.caipos.util.DateTimeUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * 传感器采集数据--三代格式
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString(callSuper = true)
public class SensorReportEntity extends BaseSensorDataEntity implements Serializable {

    private static final long serialVersionUID = 5058888022937153218L;

    /**
     * 周期时间，拉齐显示时间
     */
    @JsonFormat(pattern = DateTimeUtil.PATTERN_DATETIME)
    @DateTimeFormat(pattern = DateTimeUtil.PATTERN_DATETIME)
    private LocalDateTime cycleTime;

    /**
     * 数据处理时间
     */
    @JsonFormat(pattern = DateTimeUtil.PATTERN_DATETIME)
    @DateTimeFormat(pattern = DateTimeUtil.PATTERN_DATETIME)
    private LocalDateTime handleTime;

    /**
     * 收到上报的时间
     */
    @JsonFormat(pattern = DateTimeUtil.PATTERN_DATETIME)
    @DateTimeFormat(pattern = DateTimeUtil.PATTERN_DATETIME)
    private LocalDateTime receiveTime;

    /**
     * 采集时间
     */
    @JsonFormat(pattern = DateTimeUtil.PATTERN_DATETIME)
    @DateTimeFormat(pattern = DateTimeUtil.PATTERN_DATETIME)
    private LocalDateTime reportTime;

    /**
     * 数值
     */
    private Double sensorValue;

    /**
     * 原始数值
     */
    private Double originalSensorValue;

    /**
     * 原始和值
     */
    private Double originalSensorSumValue;

    /**
     * 原始平均值
     */
    private Double originalSensorAvgValue;

    /**
     * 原始最小值
     */
    private Double originalSensorMinValue;

    /**
     * 原始最大值
     */
    private Double originalSensorMaxValue;

    /**
     * 几位小数
     */
    private Integer scale;


    /**
     * 采集间隔
     */
    private Integer collectInterval;

    /**
     * 计算方式，1--实时值，2--平均值，3--和值，4--最大值，5--最小值
     */
    private Integer calculationMethod;

    /**
     * 传感器设备编码
     */
    private String deviceCode;

    /**
     * 组织编码
     */
    private String organizationCode;

    /**
     * 租户ID
     */
    private String tenantId;

    /**
     * 上报周期计数
     */
    private Integer reportIntervalNum;

    @Builder
    public SensorReportEntity(String id, String sensorcode, Integer sensortype, Date thattime, Double senval, Integer confirm, String confirmman, Double val_last, Double val_sum, Double val_aver, Double val_min, Double val_max, Integer sensor_ch, String stationcode, Date inserttime, Integer handleType, Integer sendrate, String tableName, LocalDateTime cycleTime, LocalDateTime handleTime, LocalDateTime receiveTime, LocalDateTime reportTime, Double sensorValue, Double originalSensorValue, Double originalSensorSumValue, Double originalSensorAvgValue, Double originalSensorMinValue, Double originalSensorMaxValue, Integer scale, Integer collectInterval, Integer calculationMethod, String deviceCode, String organizationCode, String tenantId, Integer reportIntervalNum) {
        super(id, sensorcode, sensortype, thattime, senval, confirm, confirmman, val_last, val_sum, val_aver, val_min, val_max, sensor_ch, stationcode, inserttime, handleType, sendrate, tableName);
        this.cycleTime = cycleTime;
        this.handleTime = handleTime;
        this.receiveTime = receiveTime;
        this.reportTime = reportTime;
        this.sensorValue = sensorValue;
        this.originalSensorValue = originalSensorValue;
        this.originalSensorSumValue = originalSensorSumValue;
        this.originalSensorAvgValue = originalSensorAvgValue;
        this.originalSensorMinValue = originalSensorMinValue;
        this.originalSensorMaxValue = originalSensorMaxValue;
        this.scale = scale;
        this.collectInterval = collectInterval;
        this.calculationMethod = calculationMethod;
        this.deviceCode = deviceCode;
        this.organizationCode = organizationCode;
        this.tenantId = tenantId;
        this.reportIntervalNum = reportIntervalNum;
    }
}
